package com.charles.seckillfile.service.impl;

import com.charles.seckillfile.service.FileUploadService;
import com.charles.seckillfile.utils.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Primary
@Service
public class LocalFileUploadServiceImpl implements FileUploadService {

    @Value("${file.prefix}")
    public String localFilePrefix;
    
    @Value("${file.domain}")
    public String domain;
    
    @Value("${file.path}")
    private String localFilePath;

    @Override
    public String uploadFile(MultipartFile file) throws Exception {
        String name = FileUtils.upload(localFilePath, file);
        String url = domain + localFilePrefix + name;
        return url;
    }
}
